why and when to use functions in javascript